package yyh.guanganmen.db;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import yyh.filltheform.common.ToolKit;
import yyh.jaccard.bean.Inhosptial_idAndHerbmedPairBean;

public class Inhosptial_idAndHerbPairDB {
	private String limitingCondition;
	
	public String getLimitingCondition(String path) {
		limitingCondition = new ToolKit().run(path);
		return limitingCondition;
	}
	
	/**
	 * inhosptial_id ~  herbmed
 	 * @param case_srccode
	 * @return
	 * @throws IOException 
	 */
	public List<Inhosptial_idAndHerbmedPairBean> getPair(String path) throws IOException{
		DbUtil db = new DbUtil();
		Connection conn = null;
		PreparedStatement ps = null;
		String limit = getLimitingCondition(path);
		StringBuffer sql = new StringBuffer();
		ResultSet rs = null;
		List<Inhosptial_idAndHerbmedPairBean> pairBeans = new ArrayList<Inhosptial_idAndHerbmedPairBean>();
		try{
			conn = db.getConnection();
			sql.append("select t.inhosptial_id, t.transformed_gvalue from incase_herbmed t  ");
			sql.append("where  ");
			sql.append(limit);
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery(sql.toString());
			while(rs.next()){
				Inhosptial_idAndHerbmedPairBean bean = new Inhosptial_idAndHerbmedPairBean();
				bean.setInhosptial_id(rs.getString("inhosptial_id"));
				bean.setHerbmedname(rs.getString("transformed_gvalue"));
				pairBeans.add(bean);
			}
		}catch(SQLException e){
			e.printStackTrace();;
		}finally{
			db.closeConn(conn, ps, rs);
		}
		return pairBeans;
	}
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
